<?php

/**
 * Ignus Framework
 *
 * @author Sergey Palyanov <sergey.palyanov@gmail.com>
 * @link http://code.google.com/p/ignus-php/
 * @license http://apache.org/licenses/LICENSE-2.0
 * @package Ignus
 * @subpackage App
 * @since 0.1
 */

namespace Ignus;

/**
 * @package Ignus
 * @subpackage App
 * @since 0.8.0
 */
class Exception extends \RuntimeException
{
    /**
     * Exception constructor
     * @param string $message
     * @param int $code
     * @param \Exception|null $previous
     * @param string $file
     * @param int $line
     */
    public function __construct($message, $code = 0, \Exception $previous = null, $file = '', $line = 0)
    {
        parent::__construct($message, $code);
        if ($previous != null) {
            $this->file = $previous->getFile();
            $this->line = $previous->getLine();
            return;
        }
        elseif (empty($this->file)) {
            $this->file = $file;
            $this->line = $line;
        }
    }

    /**
     * Returns class name where exception was raised in
     * @return string
     */
    public function getClassName()
    {
        return substr(basename($this->file), 0, -4);
    }
}
